package com.mlnx.web.device.controller;

import com.mlnx.common.entity.Response;
import com.mlnx.common.entity.ResponseData;
import com.mlnx.common.form.PageForm;
import com.mlnx.device.entity.LanyaDevice;
import com.mlnx.device.pojo.form.ApDeviceForm;
import com.mlnx.device.service.LanyaDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.shan.spring.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Api(value = "AP设备接口", tags = {"AP设备接口"})
@RestController
@RequestMapping("device/ap")
public class BlueApDeviceController extends BaseController {

    @Autowired
    private LanyaDeviceService lanyaDeviceService;


    @ApiOperation("获取在线血氧设备")
    @RequestMapping(value = "/get/spo", method = {RequestMethod.GET})
    public Response getSpoDeviceInfo() {

        return result(lanyaDeviceService.getOnlineSpo());
    }

    @ApiOperation("获取在线血压设备")
    @RequestMapping(value = "/get/bp", method = {RequestMethod.GET})
    public Response getBpDeviceInfo() {

        return result(lanyaDeviceService.getOnlineBp());
    }

    @ApiOperation("获取AP数据")
    @RequestMapping(value = "", method = {RequestMethod.GET})
    public Response getApDeviceInfo(@Valid PageForm pageForm, @Valid ApDeviceForm apDeviceForm) {
        ResponseData response = new ResponseData();
        response.setObj(lanyaDeviceService.listPage(pageForm,apDeviceForm));

        return response;

    }

    @ApiOperation("新增AP")
    @RequestMapping(value = "", method = {RequestMethod.POST})
    public Response addAp(LanyaDevice lanyaDevice) {
        lanyaDeviceService.save(lanyaDevice);
        return result();

    }

    @ApiOperation("更新AP")
    @RequestMapping(value = "{id}", method = {RequestMethod.PUT})
    public Response updateAp(@Valid LanyaDevice lanyaDevice, @PathVariable("id") Integer id) {
        lanyaDevice.setId(id);
        lanyaDeviceService.updateById(lanyaDevice);
        return result();

    }

    @ApiOperation("删除AP")
    @RequestMapping(value = "", method = {RequestMethod.DELETE})
    public Response deleteAp( @RequestParam(value = "ids", required = true) List<Integer> ids) {
        lanyaDeviceService.removeByIds(ids);
        return result();

    }
}
